package com.mobi.cacti.rabbit.response;

import java.util.ArrayList;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import android.util.Log;

public class ReqRssItemHandler extends DefaultHandler {
	
	private String tempVal;
	private ReqRssItem oClass;
	private ArrayList<ReqRssItem> rssItemList;
	

	public ArrayList<ReqRssItem> getObj() {
		return rssItemList;
	}
	
	public void startElement(String uri, String localName, String qName,Attributes attributes) throws SAXException {
		tempVal = "";
		
//		Log.i("tai",">>>" + localName);
		
		if (localName.equalsIgnoreCase("channel")) {
			rssItemList = new ArrayList<ReqRssItem>();
		}
		else if (localName.equalsIgnoreCase("item")) {
			oClass = new ReqRssItem();
		}
		
		
	}

	public void characters(char[] ch, int start, int length) throws SAXException {
		tempVal = new String(ch, start, length);
	}

	public void endElement(String uri, String localName, String qName) throws SAXException 
	{
//		Log.i("tai","<<<" + qName);

		if (qName.equalsIgnoreCase("item")){
			if(oClass != null)
			{
				if(oClass.link != null && !oClass.link.equals(""))
				{
					rssItemList.add(oClass);
				}
			}
		}
		else if (qName.equalsIgnoreCase("title")){
			if(oClass != null)
				oClass.title = tempVal;
		}
		if (qName.equalsIgnoreCase("link")){
			if(oClass != null)
				oClass.link = tempVal;
		}
	}

}
